﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using NASA.BeAMartian.TagGraph.Surveying;
using System.Windows.Media.Imaging;

namespace NASA.BeAMartian
{
	public partial class CategoryButtonRover : UserControl
    {
        public event EventHandler MouseEnterInfo;
        public event EventHandler MouseLeaveInfo;

        public static readonly DependencyProperty HeaderTextProperty =
            DependencyProperty.Register("HeaderText", typeof(string), typeof(CategoryButtonRover), new PropertyMetadata(new PropertyChangedCallback(HeaderText_Changed)));

        [System.ComponentModel.Category("HeaderText"), System.ComponentModel.Description("The first line of text.")]
        public string HeaderText
        {
            get { return (string)GetValue(HeaderTextProperty); }
            set { SetValue(HeaderTextProperty, value); }
        }

        private static void HeaderText_Changed(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
        {
            CategoryButtonRover eBtn = (CategoryButtonRover)dependencyObject;
            eBtn.UpdateText((string)eventArgs.NewValue);
        }

        public void UpdateText(string text)
        {
            if (header != null)
                header.Text = text;
        }


        public static readonly DependencyProperty TagCountProperty =
            DependencyProperty.Register("TagCount", typeof(string), typeof(CategoryButtonRover), new PropertyMetadata(new PropertyChangedCallback(TagCount_Changed)));

        [System.ComponentModel.Category("TagCount"), System.ComponentModel.Description("The first line of text.")]
        public string TagCount
        {
            get { return (string)GetValue(TagCountProperty); }
            set { SetValue(TagCountProperty, value); }
        }

        private static void TagCount_Changed(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
        {
            CategoryButtonRover eBtn = (CategoryButtonRover)dependencyObject;
            eBtn.UpdateCountText((string)eventArgs.NewValue);
        }

        public void UpdateCountText(string text)
        {
            if (tagCount != null)
                tagCount.Text = text;
        }





        public static readonly DependencyProperty ImageTagProperty =
            DependencyProperty.Register("ImageTag", typeof(ImageFeature), typeof(CategoryButtonRover), new PropertyMetadata(null));

        [System.ComponentModel.Category("ImageTag"), System.ComponentModel.Description("The image tag.")]
        public ImageFeature ImageTag
        {
            get { return (ImageFeature)GetValue(ImageTagProperty); }
            set { SetValue(ImageTagProperty, value); }
        }

        TextBlock header;
        TextBlock tagCount;

        private void tb_Loaded(object sender, RoutedEventArgs e)
        {
            //header = sender as TextBlock;
            //header.Text = HeaderText;
        }

        private void tbCount_Loaded(object sender, RoutedEventArgs e)
        {
            tagCount = sender as TextBlock;
        }
        public CategoryButtonRover()
        {
            // Required to initialize variables
            InitializeComponent();
        }

        private void InfoIcon_MouseEnter(object sender, MouseEventArgs e)
        {
            if (MouseEnterInfo != null)
                MouseEnterInfo(ImageTag, EventArgs.Empty);
        }

        private void InfoIcon_MouseLeave(object sender, MouseEventArgs e)
        {
            if (MouseLeaveInfo != null)
                MouseLeaveInfo(ImageTag, EventArgs.Empty);
        }

        private void Image_Loaded(object sender, RoutedEventArgs e)
        {
            Image img = sender as Image;
            img.Source = new BitmapImage(new Uri("Rover.png", UriKind.RelativeOrAbsolute));

            //if (ImageTag.TagType != ImageTagTypes.Land)
            //    img.Height = 18;

            //if (ImageTag.TagType == ImageTagTypes.Sky)
            //    img.Width = 16;
        }

        Border brd;

        private void border_Loaded(object sender, RoutedEventArgs e)
        {
            //brd = sender as Border;
            //colorBackground(0);

            //if (ImageTag.TagType == ImageTagTypes.Land)
            //    brd.Background = new SolidColorBrush(Color.FromArgb(165, 167, 59, 11));
        }

        private void ToggleButton_Checked(object sender, RoutedEventArgs e)
        {
            //colorBackground(255);
        }

        private void ToggleButton_Unchecked(object sender, RoutedEventArgs e)
        {
            //colorBackground(0);

            //if (ImageTag.TagType == ImageTagTypes.Land)
            //    brd.Background = new SolidColorBrush(Color.FromArgb(200, 167, 59, 11));
        }

        void colorBackground(byte opacity)
        {
            if (ImageTag.TagType == ImageTagTypes.Sky)
                brd.Background = new SolidColorBrush(Color.FromArgb(opacity, 9, 109, 226));

            if (ImageTag.TagType == ImageTagTypes.Rover)
                brd.Background = new SolidColorBrush(Color.FromArgb(opacity, 19, 124, 28));

            if (ImageTag.TagType == ImageTagTypes.Land)
                brd.Background = new SolidColorBrush(Color.FromArgb(opacity, 167, 59, 11));
        }
	}
}